package edu.fdzc.mapper;

import edu.fdzc.pojo.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeptMapper {
    //方式1：手动结果映射
//    @Results({
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
    /**
     * 查询部门列表
     */
    @Select("SELECT id, `name`, create_time, update_time FROM `dept` ORDER BY update_time DESC")
    List<Dept> findall();

    /**
     * 根据id删除部门
     */
    @Delete("delete from dept where id = #{id}")
    void deleteById(Integer id);

    /**
     * 保存部门
     */
    @Insert("INSERT into dept(name,create_time,update_time) values (#{name}, #{createTime}, #{updateTime})")
    void add(Dept dept);

    /**
     * 修改部门
     */
    @Select("SELECT id, `name`, create_time, update_time FROM `dept` where id = #{id}")
    Dept getById(Integer id);

    /**
     * 修改部门
     */
    @Update("update dept set name = #{name},update_time = #{updateTime} where id = #{id}")
    void update(Dept dept);
}
